<?php
/**
 * Created by PhpStorm.
 * User: tangping
 * Date: 16/4/24
 * Time: 下午10:56
 */

namespace Events;
use Phalcon\Mvc\User\Plugin;

class Base extends  Plugin
{
    public static  function afterUpdate($model=''){
        if(empty($model) || !is_array($model)){
            return -11;
        }
        $model=unserialize($model['data']);
        return @$model?$model:-11;
    }


    public static function getPK($model=''){

        $metaData = new \Phalcon\Mvc\Model\MetaData\Memory();
        $attributes = $metaData->getPrimaryKeyAttributes($model);

        return $attributes[0];
    }

    public static function getBefore($key=''){
        $before=Common::getTable($key);
        if($before !==false){
            Common::delTable($key);
        }
        return json_decode($before['data'],true);
    }

}